package utils

import (
	"math/rand"
	"time"
)

// 打乱算法
func Shuffle(arr []int)[]int{
	rand.Seed(time.Now().UnixNano())

	var i, j int
	var temp int
	for i = len(arr) - 1; i > 0; i-- {
		j = rand.Intn(i + 1)
		temp = arr[i]
		arr[i] = arr[j]
		arr[j] = temp
	}
	return arr

}

func GetRand(proArr []int) int{
	rand.Seed(time.Now().UnixNano())
	proSum:=0
	for _,v:=range proArr{
		proSum=proSum+v
	}
	rid:=0
	for key,Odd:=range proArr{
		randNum:=rand.Intn(proSum)
		if(randNum <= Odd){
			rid=key
			break
		}else{
			proSum=proSum-Odd
		}
	}
	return rid
}
